﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DeviceSDK.LED.LingXin
{
    public class LingXin_Q3
    {
        //获取错误代码
        public static string Get_Error(int ret)
        {
            switch (ret)
            { 
                case 0:
                    return "操作成功！";
                case 1:
                    return "操作失败！";
                case -1:
                    return "本设备不支持此命令！";
                default:
                    return "未知错误！";
            }
         }

        //重启
        public static int Set_Reboot(string IP)
        {

            int ret =LX_DeleteTheProgram(1,  IP);
            for (int j = 0; j < 255; j++)
            {
                ret = LX_DeleteTheFile(0, 0, j, IP);
            }
            
            LX_DeleteTheProgram(0, IP);
            return 0;
        }

        //设置-屏幕-关闭
        public static int Set_Screen_Close(string IP)
        {
            return LingXin_SDK.ScreenON_OFF(IP, 0) ? 0:1;
        }

        //设置-屏幕-开启
        public static int Set_Screen_Open(string IP)
        {
            return LingXin_SDK.ScreenON_OFF(IP, 1) ? 0:1;
        }


        //设置-屏幕亮度
        public static int Set_Brightness(string IP, int Value)
        {
            return LingXin_SDK.AdjustBright(IP, Value) ? 0:1;
        }

        //设置-时间
        public static int Set_Time(string IP)
        {
            return LingXin_SDK.AdjustTime(IP)?0:1;
        }

        //发送-节目
        public static int Send_Programs(string IP, PlaybillProgramInfo[] Programs)
        {

            int ret=0;

            //if(IsPlayBillUpdate)
                LX_DeleteTheProgram(0, IP);

            foreach (PlaybillProgramInfo pinfo in Programs)
            {
                pinfo.IsEffectRand = pinfo.IsEffectRand == 0 ? 0 : -1;
                //LX_DeleteTheFile(0,pinfo.ScreenAreaID ,pinfo.ID,IP);

                //int FileType = ToolsHelper.GetFileType(pinfo.FilePath);

                switch (pinfo.Type)
                {
                    case "picture":
                        LX_AddPictureArea(0, "",0, true, pinfo.ScreenAreaID  , pinfo.X, pinfo.Y, pinfo.Width, pinfo.Height, "", pinfo.ID, pinfo.FilePath, pinfo.IsEffectRand, 1, pinfo.PlayTime, 1, 1, IP);
                        break;

                    case "video":
                        LX_AddVideoArea(0, "", 0, true, pinfo.ScreenAreaID, pinfo.X, pinfo.Y, pinfo.Width, pinfo.Height, "", pinfo.ID, pinfo.FilePath, 0, 0, 0, 0, 0, 0, 1, IP);
                        break;

                    case "rtf":
                        LX_AddTextArea(0, "", 0, true, pinfo.ScreenAreaID, pinfo.X, pinfo.Y, pinfo.Width, pinfo.Height, "", 0, 0, 0, 0, pinfo.ID, pinfo.FilePath, pinfo.IsEffectRand, 1, pinfo.PlayTime, 1, 1, 0, IP);
                        break;

                    case "text":
                        LX_AddStringTxtArea(0, "", 0, true, pinfo.ScreenAreaID, pinfo.X, pinfo.Y, pinfo.Width, pinfo.Height, "", 0, 0, 0, 0, pinfo.ID, pinfo.IsEffectRand, pinfo.EffectTime, pinfo.PlayTime, pinfo.IsEffectRand, pinfo.EffectTime, pinfo.LineSpace, pinfo.GetFontColorInt(), pinfo.FontName, pinfo.FontSize, pinfo.FontIsBold, false, false, pinfo.FontAlign, pinfo.Text, IP);
                        break;
                }
            }

            ret= LX_SendProgram(IP, 0, 0, 0);
            return ret;
        }

        //public static int Send_Text(string IP)
        //{
        //    LX_DeleteTheProgram(0, IP);
        //    LingXin_SDK.AddStringTxtArea(0,"",0, true, 0, 0, 0, 192, 160, "", 0, 0, 0, 0,15, 7, 35, 0, 5, 5, 0, 0xf0, "黑体", 12, false, false, false, 0, "测试文字12345   ABCDE",IP);
        //    int ret= LX_SendProgram(IP, 0, 0, 0);
        //    return ret;

        //}

        /// <summary>
        /// 开关机
        /// </summary>
        /// <param name="strIP">通讯IP地址（播放盒IP）</param>
        /// <param name="op">操作码：0表示关机，1表示开机</param>
        /// <returns>False失败 True成功</returns>
        public static int LX_ScreenON_OFF(string strIP, int op)
        {
            return LingXin_SDK.ScreenON_OFF(strIP,op)?1:0;
        }

        public static int LX_AddStringTxtArea(int program_id, string programname, int playtime, bool waitfinish, int area_id, int x, int y, int w, int h, string areaname, int edge_degree, uint edge_color, int bk_mode, uint bk_color, int file_id, int moveintype, int moveinspeed, int remain, int moveouttype, int moveoutspeed, int linespace, int fontColor, string fontName, int fontSize, bool isBold, bool isItalic, bool isUnderline, string horAlign, string Text, string strIP)
        {
            int align = 0;
            switch (horAlign)
            {
                case "LEFT": align = 1; break;
                case "RIGHT": align = 2; break;
                case "CENTER": align = 3; break;
                default: align = 3; break;
            }
            return LingXin_SDK.AddStringTxtArea(program_id, programname, playtime, waitfinish, area_id, x, y, w, h, areaname, edge_degree, edge_color, bk_mode, bk_color, file_id, moveintype, moveinspeed, remain, moveouttype, moveoutspeed, linespace, (uint)fontColor, fontName, fontSize, isBold, isItalic, isUnderline, align, Text, strIP) ? 0 : 1;
        }
        /// <summary>
        /// 添加文本
        /// </summary>
        /// <param name="program_id">节目序号</param>
        /// <param name="programname">节目名字</param>
        /// <param name="playtime">播放时间</param>
        /// <param name="waitfinish">是否等待播放节目完成</param>
        /// <param name="area_id">区域序号</param>
        /// <param name="x">区域左上角x坐标</param>
        /// <param name="y">区域左上角y坐标</param>
        /// <param name="w">区域宽</param>
        /// <param name="h">区域高</param>
        /// <param name="areaname">区域名字</param>
        /// <param name="edge_degree">边框粗细</param>
        /// <param name="edge_color">边框颜色</param>
        /// <param name="bk_mode">背景模式</param>
        /// <param name="bk_color">背景颜色</param>
        /// <param name="file_id">文件序号</param>
        /// <param name="textpath">文件全路径</param>
        /// <param name="moveintype">进入特效方式</param>
        /// <param name="moveinspeed">进入特效速度</param>
        /// <param name="remain">停留时间</param>
        /// <param name="moveouttype">退出特效方式</param>
        /// <param name="moveoutspeed">退出特效速度</param>
        /// <param name="linespace">行间距</param>
        /// <param name="StrIP">播放盒IP地址</param>
        /// <returns>False失败 True成功</returns>
        public static int LX_AddTextArea(int program_id, string programname, int playtime, bool waitfinish, int area_id, int x, int y, int w, int h, string areaname, int edge_degree, int edge_color, int bk_mode, int bk_color, int file_id, string textpath, int moveintype, int moveinspeed, int remain, int moveouttype, int moveoutspeed, int linespace, string StrIP)
        {
            return LingXin_SDK.AddTextArea(program_id, programname, playtime, waitfinish, area_id, x, y, w, h, areaname, edge_degree, edge_color, bk_mode, bk_color, file_id, textpath, moveintype, moveinspeed, remain, moveouttype, moveoutspeed, linespace, StrIP) ? 0:1;
        }
        /// <summary>
        /// 添加图片
        /// </summary>
        /// <param name="program_id">节目序号</param>
        /// <param name="programname">节目名字</param>
        /// <param name="playtime">播放时间</param>
        /// <param name="waitfinish">是否等待播放节目完成</param>
        /// <param name="area_id">区域序号</param>
        /// <param name="x">区域左上角x坐标</param>
        /// <param name="y">区域左上角y坐标</param>
        /// <param name="w">区域宽</param>
        /// <param name="h">区域高</param>
        /// <param name="areaname">区域名字</param>
        /// <param name="file_id">文件序号</param>
        /// <param name="picpath">文件全路径</param>
        /// <param name="moveintype">进入特效方式</param>
        /// <param name="moveinspeed">进入特效速度</param>
        /// <param name="remain">停留时间</param>
        /// <param name="moveouttype">退出特效方式</param>
        /// <param name="moveoutspeed">退出特效速度</param>
        /// <param name="StrIP">播放盒IP地址</param>
        /// <returns>False失败 True成功</returns>
        public static int LX_AddPictureArea(int program_id, string programname, int playtime, bool waitfinish, int area_id, int x, int y, int w, int h, string areaname, int file_id, string picpath, int moveintype, int moveinspeed, int remain, int moveouttype, int moveoutspeed, string StrIP)
        {
            return LingXin_SDK.AddPictureArea(program_id, programname, playtime, waitfinish, area_id, x, y, w, h, areaname, file_id, picpath, moveintype, moveinspeed, remain, moveouttype, moveoutspeed, StrIP) ? 0:1;
        }
        /// <summary>
        /// 添加视频
        /// </summary>
        /// <param name="program_id">节目序号</param>
        /// <param name="programname">节目名字</param>
        /// <param name="playtime">播放时间</param>
        /// <param name="waitfinish">是否等待播放节目完成</param>
        /// <param name="area_id">区域序号</param>
        /// <param name="x">区域左上角x坐标</param>
        /// <param name="y">区域左上角y坐标</param>
        /// <param name="w">区域宽</param>
        /// <param name="h">区域高</param>
        /// <param name="areaname">区域名字</param>
        /// <param name="file_id">文件序号</param>
        /// <param name="videopath">文件全路径</param>
        /// <param name="videosource_x">压缩x坐标</param>
        /// <param name="videosource_y">压缩y坐标</param>
        /// <param name="videosource_w">压缩宽</param>
        /// <param name="videosource_h">压缩高</param>
        /// <param name="videoorg_x">源视频宽</param>
        /// <param name="videoorg_y">源视频高</param>
        /// <param name="showmode">显示模式 0：显示全部视频 1：撑满整个屏幕</param>
        /// <param name="StrIP">播放盒IP地址</param>
        /// <returns>False失败 True成功</returns>
        public static int LX_AddVideoArea(int program_id, string programname, int playtime, bool waitfinish, int area_id, int x, int y, int w, int h, string areaname, int file_id, string videopath, int videosource_x, int videosource_y, int videosource_w, int videosource_h, int videoorg_x, int videoorg_y, int showmode, string StrIP)
        {
            return LingXin_SDK.AddVideoArea(program_id, programname, playtime, waitfinish, area_id, x, y, w, h, areaname, file_id, videopath, videosource_x, videosource_y, videosource_w, videosource_h, videoorg_x, videoorg_y, showmode, StrIP) ? 0:1;
        }

        /// <summary>
        /// 节目发送
        /// </summary>
        /// <param name="strIP">播放盒通讯IP地址</param>
        /// <param name="pNull1">回调函数</param>
        /// <param name="pNull2">回调函数的参数</param>
        /// <param name="ProgramID">文件类型，0素材文件，1预存节目一（video1），2预存节目二（video2）</param>
        /// <returns>False失败 True成功</returns>
        public static int LX_SendProgram(string strIP, int pNull1, int pNull2, int ProgramID)
        {
            return LingXin_SDK.SendProgram(strIP, pNull1, pNull2, ProgramID) ? 0:1;
        }
        /// <summary>
        /// 删除节目
        /// </summary>
        /// <param name="program_id">节目序号</param>
        /// <param name="StrIP">播放盒IP地址</param>
        /// <returns>False失败 True成功</returns>
        public static int LX_DeleteTheProgram(int program_id, string StrIP)
        {
            return LingXin_SDK.DeleteTheProgram(program_id, StrIP) ? 0:1;
        }
        /// <summary>
        /// 删除节目
        /// </summary>
        /// <param name="program_id">节目序号</param>
        /// <param name="area_id">区域序号</param>
        /// <param name="StrIP">播放盒IP地址</param>
        /// <returns>False失败 True成功</returns>
        public static int LX_DeleteTheArea(int program_id, int area_id, string StrIP)
        {
            return LingXin_SDK.DeleteTheArea(program_id, area_id, StrIP) ? 0:1;
        }
        /// <summary>
        /// 删除节目
        /// </summary>
        /// <param name="program_id">节目序号</param>
        /// <param name="area_id">区域序号</param>
        /// <param name="file_id">文件序号</param>
        /// <param name="StrIP">播放盒IP地址</param>
        /// <returns>False失败 True成功</returns>
        public static int LX_DeleteTheFile(int program_id, int area_id, int file_id, string StrIP)
        {
            return LingXin_SDK.DeleteTheFile(program_id, area_id, file_id, StrIP) ? 0:1;
        }
        /// <summary>
        /// 手动调节亮度
        /// </summary>
        /// <param name="StrIP"> IP地址</param>
        /// <param name="Value">亮度值（0~255）0最暗，255最亮</param>
        /// <returns>False失败 True成功</returns>
        public static int LX_AdjustBright(string StrIP, int Value)
        {
            return LingXin_SDK.AdjustBright(StrIP,Value)?1:0;
        }
    }

}
